﻿package Game.PlaySystem{
	import Game.Manager;
	import Game.PlaySystem.Player;
	import Game.PlaySystem.TurnManager;
	import Game.Utils.T;
	
	public class PlayManager extends Manager{
		//Tableau contenant tous les objets Players de la partie.
		private var m_Players:Array;
		
		//TurnManager , qui soccupera de gérer les tours (et peut-etre aussi les actions ?)
		private var m_TurnManager:TurnManager;
		
		public function PlayManager(_parentObj:*){
			super(_parentObj);			
		}
		public function InitTurnManager(_stateFileAdress:String):void{
			m_TurnManager = new TurnManager(this,_stateFileAdress);
		}
		public function EndTurn(_actions:Array = null):void{
			var player:Player;
			if(!_actions){
				player= getNextPlayer();
				//T.Trace (player);
			}
			var resultStr:String= player.askToPlay();
			if(resultStr == 'human'){
				Parent.setState(Parent.PLAYING_STATE);
			}
			
			
		}
		private var currentPlayer:int=-1;
		public function getNextPlayer():Player{
			currentPlayer ++ ;
			if (currentPlayer >= m_Players.length){
				currentPlayer= 0;
			}
			return m_Players[currentPlayer];
		}
		public function createPlayers(_players:Array):void{
			m_Players= new Array();
			for(var i:int=0;i<_players.length;i++){
				m_Players[i] = new Player(_players[i][0],_players[i][1]);
				T.Trace (m_Players[i]);
			}
		}
		public function isCurrentPlayer(_player:Player = null):Boolean{
			if(_player == null){
				if(true){//Tester si le joueur en cours est le joueur qui joue (if currentPaleyer == moi).
					return true;
				}
			}
			return false;
		}
	}
}